<?php
// +----------------------------------------------------------------------
// | 众联TK架构 [ ZoomTk ]
// +----------------------------------------------------------------------
// | 版权所有 2017~2037 成都众联思索科技有限公司 [ http://www.zoomtk.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.sopvip.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\mall\admin;
use app\common\builder\TKuitpl;
use app\mall\common\Adminbase;
use think\Model;
use think\Cache;
use think\Db;

/**
 * 评价管理
 * @package app\mall\admin
 */
class Evaluate  extends Adminbase
{
    /**
     * 首页
     * @author Sunday <153788231@qq.com>
     * @return mixed
     */
    public function index()
    {
        $model_evaluate_goods = Model('evaluategoods');
        $condition = array();
        if ($_POST['query'] != '' && in_array($_POST['qtype'],array('geval_frommembername','geval_goodsname','geval_storename'))) {
            $condition[$_POST['qtype']] = array('like',"%{$_POST['query']}%");
        }
        $sort_fields = array('geval_id','geval_frommembername','geval_scores','geval_addtime','geval_orderno','geval_frommemberid','geval_storeid','geval_goodsid');
        if ($_POST['sortorder'] != '' && in_array($_POST['sortname'],$sort_fields)) {
            $order = $_POST['sortname'].' '.$_POST['sortorder'];
        }
        $evalgoods_list = $model_evaluate_goods->getEvaluateGoodsList($condition,$order);
        $page= $evalgoods_list->render();

        foreach ($evalgoods_list as $k => $evalgoods_info) {
            $list = array();
            $list['geval_id'] = $evalgoods_info['geval_id'];
            $list['operation'] = "<a class='btn red' onclick=\"fg_delete({$evalgoods_info['geval_id']})\"><i class=\"fa fa-trash-o\"></i>删除</a>";
            $list['geval_frommembername'] = $evalgoods_info['geval_frommembername'];
            $list['geval_scores'] = "<span class=\"raty\" data-score=\"{$evalgoods_info['geval_scores']}\"></span>";
            $list['geval_content'] = "<span class='fa' title='{$evalgoods_info['geval_content']}'>{$evalgoods_info['geval_content']}</span>";
//            if(!empty($evalgoods_info['geval_image'])) {
//                $image_array = explode(',', $evalgoods_info['geval_image']);
//                foreach ($image_array as $value) {
//                    $list['geval_image'] .= "<li><a nctype=\"nyroModal\"  href=\"".snsThumb($value, 1024)."\"> <img src=\"".snsThumb($value)."\"> </a></li>";
//                }
//                $list['geval_image'] = '<ul class="evaluation-pic-list">'.$list['geval_image'].'</ul>';
//            } else {
//                $list['geval_image'] = '';
//            }
            $list['geval_addtime'] = date('Y-m-d',$evalgoods_info['geval_addtime']);
            $list['geval_goodsname'] = "<a class='open' title='{$evalgoods_info['geval_goodsname']}' href='". url('goods/index', array('goods_id' => $evalgoods_info['geval_goodsid'])) ."' target='blank'>{$evalgoods_info['geval_goodsname']}</a>";
            $list['geval_storename'] = "<a class='open' title='{$evalgoods_info['geval_storename']}' href='". url('show_store/index', array('store_id'=>$evalgoods_info['geval_storeid'])) ."' target='blank'>{$evalgoods_info['geval_storename']}</a>";
            $list['geval_orderno'] = $evalgoods_info['geval_orderno'];
            $list['geval_frommemberid'] = $evalgoods_info['geval_frommemberid'];
            $list['geval_storeid'] = $evalgoods_info['geval_storeid'];
            $list['geval_content_again'] = "<span class='fa' title='{$evalgoods_info['geval_content_again']}'>{$evalgoods_info['geval_content_again']}</span>";
//            if(!empty($evalgoods_info['geval_image_again'])) {
//                $image_array = explode(',', $evalgoods_info['geval_image_again']);
//                foreach ($image_array as $value) {
//                    $list['geval_image_again'] .= "<li><a nctype=\"nyroModal\"  href=\"".snsThumb($value, 1024)."\"> <img src=\"".snsThumb($value)."\"> </a></li>";
//                }
//                $list['geval_image_again'] = '<ul class="evaluation-pic-list">'.$list['geval_image_again'].'</ul>';
//            } else {
//                $list['geval_image_again'] = '';
//            }
            $data[$evalgoods_info['geval_id']] = $list;
        }
        // 使用TKuitpl快速创建数据表格
        return TKuitpl::make('table')
            ->setPageTitle('评价管理')// 设置页面标题
            ->addTopButtons('add') // 批量添加顶部按钮
            ->addTopButtons('delete') // 批量添加顶部按钮
            ->setPrimaryKey('geval_id') // 设置主键名为username
            ->setSearch(['type_id' => '类型ID', 'type_name' => '类型名称'])// 设置搜索参数
            ->addOrder('type_id,type_name') // 添加排序
            ->addColumns([ // 批量添加列
                ['geval_id', '评价ID'],
                ['geval_frommembername', '评价人'],
                ['geval_content', '评价内容'],
                ['class_id', '晒单图片'],
                ['geval_addtime', '平均时间'],
                ['geval_goodsname', '平均商品'],
                ['geval_storename', '平均商家'],
//                ['class_name', '追平内容'],
//                ['class_name', '追评晒单'],
                ['right_button', '操作', 'btn']
            ])
            ->addRightButtons('edit,delete')// 批量添加右侧按钮
            ->setRowList($data)// 设置表格数据
            ->setPages($page)// 设置分页数据
            ->fetch(); // 渲染页面
    }
}


